//
//  NSString+Expand.m
//  AnimeShopping
//
//  Created by mac on 2017/12/17.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "NSString+ZXExpand.h"

@implementation NSString (ZXExpand)

#pragma mark - Base64解码
+(NSString *)Base64DecodingString:(NSString *)base64{
    NSData *decodedData = [[NSData alloc] initWithBase64EncodedString:base64 options:0];
    NSString *decodedString = [[NSString alloc] initWithData:decodedData encoding:NSUTF8StringEncoding];
    return decodedString;
}
#pragma mark - Base64编码
+(NSString *)Base64EncodingString:(NSString *)string{
    NSData *plainData = [string dataUsingEncoding:NSUTF8StringEncoding];
    NSString *base64String = [plainData base64EncodedStringWithOptions:0];
    return base64String;
}
#pragma mark - 验证手机号
+(BOOL)checkUserMobile:(NSString *)mobile{
    //手机
    NSString *regex = @"^1([0-9][0-9])\\d{8}$";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    BOOL isMatch = [pred evaluateWithObject:mobile];
    if ((isMatch)) {
        return YES;
    }else{
        return NO;
    }
}
#pragma mark -  字符串模糊查询
+(BOOL)FuzzySearchWith:(NSString *)All WithSearchText:(NSString *)searchText{
    BOOL isContains = YES;
    for (NSInteger i = 0; i < searchText.length ; i ++ ) {
        NSRange range = NSMakeRange(i, 1);
        NSString *key = [searchText substringWithRange:range];
        if ([All rangeOfString:key].location == NSNotFound) {
            isContains = NO;
            break;
        }
    }
    return isContains;
}
#pragma mark - 字符串是否为NULL
+(BOOL)isBlankString:(NSString *)aStr{
    if (!aStr) {
        return YES;
    }
    if ([aStr isKindOfClass:[NSNull class]]) {
        return YES;
    }
    if (!aStr.length) {
        return YES;
    }
    NSCharacterSet *set = [NSCharacterSet whitespaceAndNewlineCharacterSet];
    NSString *trimmedStr = [aStr stringByTrimmingCharactersInSet:set];
    if (!trimmedStr.length) {
        return YES;
    }
    return NO;
}

@end
